package com.hc.bank.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class BaseDao {

	/**
	 * @author dlb
	 * @return Connection
	 * @time 2016 下午2:56:56
	 * @desc 获得数据库连接
	 * 
	 */
	public Connection getConnection() {
		Connection connection = null;
		try {
			Class.forName(MyCon.DRIVER);
			connection = DriverManager.getConnection(MyCon.URL, MyCon.USER, MyCon.PASSWORD);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return connection;
	}

	/**
	 * @author dlb
	 * @param rs
	 *            ResultSet
	 * @param ps
	 *            PreparedStatement
	 * @param connection
	 *            Connection
	 * @return void
	 * @time 2016 下午2:57:30
	 * @desc 关闭数据库连接
	 * 
	 */
	public void closeAll(ResultSet rs, PreparedStatement ps, Connection connection) {

		if (null != rs) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (null != ps) {
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (null != connection) {
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
